import com.calculator.NegativeException;
import com.calculator.StringCalculatorApp;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

/**
 * Created with IntelliJ IDEA.
 * User: Thoughtworker
 * Date: 8/21/13
 * Time: 1:39 PM
 * To change this template use File | Settings | File Templates.
 */
public class StringCalculatorTest {

    @org.junit.Test
    public void shouldReturnZeroWhenInputIsEmpty() throws Exception {
        StringCalculatorApp stringCalculatorApp = new StringCalculatorApp();
        assertThat(stringCalculatorApp.add(""), is(0));
    }

    @Test
    public void shouldReturnOneWhenInputIsOne() throws Exception {
        StringCalculatorApp stringCalculatorApp = new StringCalculatorApp();
        assertThat(stringCalculatorApp.add("1"), is(1));
    }

    @Test
    public void shouldReturnThreeWhenInputIsOneAnDTwo() throws Exception {
        StringCalculatorApp stringCalculatorApp = new StringCalculatorApp();
        assertThat(stringCalculatorApp.add("1,2"), is(3));
    }

    @Test
    public void shouldReturnThreeWhenNumberOfNumbersIsUnknown() throws Exception {
        StringCalculatorApp stringCalculatorApp = new StringCalculatorApp();
        assertThat(stringCalculatorApp.add("1,2,5,6"), is(14));
    }

    @Test
    public void shouldReturn6WhenInputHasNewLines() throws Exception {
        StringCalculatorApp stringCalculatorApp = new StringCalculatorApp();
        assertThat(stringCalculatorApp.add("1\n2,3"), is(6));
    }

    @Test
    public void shouldReturnDelimiterIfThereIsDelimiter() throws Exception {
        StringCalculatorApp stringCalculatorApp = new StringCalculatorApp();
        assertThat(stringCalculatorApp.getDelimiter("//[*+*]\n1*+*2*+*3"), is("*+*"));
    }

    @Test
    public void shouldReturnJustNumbersIfDifferentDelimiter() throws Exception {
        StringCalculatorApp stringCalculatorApp = new StringCalculatorApp();
        assertThat(stringCalculatorApp.getAfterDelimiter("//[***]\n1***2***3"), is("1***2***3"));

    }

    @Test
    public void shouldReturn6WhenHavingDifferentDelimiter() throws Exception {
        StringCalculatorApp stringCalculatorApp = new StringCalculatorApp();
        assertThat(stringCalculatorApp.add("//[$]\n1$2$3"), is(6));

    }

    @Test(expected = NegativeException.class)
    public void shouldThrowExceptionWhenNegativeNumbers() throws NegativeException {
        StringCalculatorApp stringCalculatorApp = new StringCalculatorApp();
        stringCalculatorApp.add("//[$]\n-1$2$3");

    }

    @Test
    public void shouldIgnoreNumbersGreaterThan1000() throws Exception {
        StringCalculatorApp stringCalculatorApp = new StringCalculatorApp();
        assertThat(stringCalculatorApp.add("//[$]\n1$1001$2$1000$3$999"), is(2005));
    }


}
